package com.cskaoyan.service.wx;

import com.cskaoyan.bean.CategoryId;
import com.cskaoyan.bean.Goods;
import com.cskaoyan.bean.wxbean.WxHomeBean.GoodsListBean;
import com.cskaoyan.mapper.wx.CategoryMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Enzo Cotter on 2020/10/8.
 */
@Service
public class CategoryServiceImpl implements  CategoryService {
    @Autowired
    CategoryMapper categoryMapper;
    @Override
    public Integer queryPidById(Integer currentSubCategoryId) {
        return categoryMapper.queryPidById(currentSubCategoryId);
    }

    @Override
    public List<CategoryId> queryAllCategoriesL2(Integer parentCategoryId) {
        return categoryMapper.queryAllCategoriesL2(parentCategoryId);
    }

    @Override
    public CategoryId getCategoryById(Integer currentSubCategoryId) {
        return categoryMapper.selectByPrimaryKey(currentSubCategoryId);
    }


    @Override
    public Map<String, Object> queryWxRelatedList(Integer id) {
        Map<String, Object> data = new LinkedHashMap<>();
        Goods goods = categoryMapper.selectGoodsById(id);
        Integer categoryId = goods.getCategoryId();
        List<GoodsListBean> goodsList = categoryMapper.queryListByIdWithLimit(categoryId, 6);
        data.put("goodsList", goodsList);
        return data;
    }

    @Override
    public List<GoodsListBean> queryGoodsListById(Integer categoryId) {
        return categoryMapper.queryGoodsListById(categoryId);
    }

    @Override
    public List<CategoryId> queryCategoryListByKeyWord(String order, String sort, String keyword) {
        return categoryMapper.queryCategoryListByKeyWord(order,sort,keyword);
    }

    @Override
    public List<GoodsListBean> queryGoodsListByKeyWord(String order, String sort, String keyword) {
       return categoryMapper.selectGoodsListByKeyWord(order,sort,keyword);
    }
}
